import React, { useEffect, useState } from "react";
import { StyleSheet, View, Text, ImageBackground } from "react-native";
import { scaleSizeW, scaleSizeH, setSpText } from "../utils/ScreenUtil";
import { get } from "../utils/Storage";
import { getToken } from "../services/user";
import { Ionicons } from "@expo/vector-icons";
export default ({ navigation }) => {
    const [user, setUser] = useState({});
    React.useEffect(() => {
        const unsubscribe = navigation.addListener("focus", async () => {
            // Screen was focused
            // Do something
            
            let {data} = await getToken();
            setUser(data);
            console.log("My",data);
        });

        return unsubscribe;
    }, [navigation]);
    return (
        <View style={styles.container}>
            <ImageBackground
                source={require("../assets/images/mybg.jpg")}
                style={styles.image}
            >
                {/* <Text style={styles.text}>Inside</Text> */}
                <View style={styles.header}>
                    <Ionicons
                        name="person"
                        size={setSpText(150)}
                        color="#bdbdbd"
                    />
                </View>
                <Text
                    onPress={() => navigation.navigate("Login")}
                    style={styles.loginText}
                >
                    {Object.keys(user).length > 0 ? user.username : "登录"}
                </Text>
            </ImageBackground>
        </View>
    );
};
const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    image: {
        // flex:1,
        width: scaleSizeW(750),
        height: scaleSizeH(400),
        resizeMode: "cover",
        flexDirection: "row",
        alignItems: "center",
        // justifyContent: "center"
    },
    header: {
        width: scaleSizeW(150),
        height: scaleSizeW(150),
        borderRadius: scaleSizeW(150),
        backgroundColor: "white",
        justifyContent: "center",
        alignItems: "center",
        marginLeft: scaleSizeW(100),
        marginRight: scaleSizeW(50),
    },
    loginText: {
        color: "white",
        fontWeight: "bold",
    },
});
